﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Agr.CQRS.Domain.Commands;
using Agr.CQRS.Domain;

namespace Tests.Agr.CQRS.Domain.Commands
{
    [TestClass]
    public class When_An_AggregateRoot_Is_Affected_During_Command_Execution
    {
        MockDomainRepository repos;
        
        [TestInitialize]
        public void TestInitialize()
        {
            //Given
            repos = new MockDomainRepository();
            var handler = new TestCommandHandler();
            handler.SetRepository(repos);

            //When
            handler.ExecuteCommand(new TestCommand());
        }

        [TestMethod]
        public void Then_The_AggregateRoot_Is_Saved_Afterwards()
        {
            Assert.IsInstanceOfType(repos.LastSaved, typeof(TestAggregateRoot));
        }

        public class TestCommand : Command
        {
        }
        public class TestCommandHandler : CommandHandler
        {
            protected override void ExecuteInternal(Command command)
            {
                var ar = GetById<TestAggregateRoot>(Guid.NewGuid(), 0);
            }
        }
        public class TestAggregateRoot : AggregateRoot
        {
        }

    }
}
